#include <iostream>
#include <vector>
using namespace std;

class Solution {
public:
    int findPeakElement(vector<int>& nums) {
        if (nums.size() == 1)
            return 0;

        int l = 1, r = nums.size() - 2;
        while (l < r) {
            int mid = l + (r - l) / 2;
            if (nums[mid] < nums[mid + 1]) {
                l = mid + 1;
            }
            else {
                r = mid;
            }
        }

        if (nums[0] > nums[1])
            return 0;
        else if (nums[nums.size() - 1] > nums[nums.size() - 2])
            return nums.size() - 1;
        return l;
    }
};

int main()
{
    vector<int> nums = { 1,2,3,1 };
    Solution().findPeakElement(nums);
    return 0;
}